<template>
    <div class="yhjlb">
      
         <div class="yhjlist" v-for="item in yhjlist">
                                <div class="pricename">￥{{ item.price }}</div>
                                <div class="syzl">适用专栏:{{ item.title }}</div>
                                <div class="syzl">有效期:{{ item.start_time }} -{{ item.end_time }}</div>
                                <div style="text-align: right;">
                                    <n-button type="primary" >立即使用</n-button>
                                 
                                </div>
                            </div>
    </div>
</template>
<script setup>
import { NButton } from 'naive-ui';

const yhjlist = ref([]);
onMounted(() => {
   
    getyhj()
})
const getyhj = async () => {
    const { data } = await useHttp("", "/user_coupon?page=1");
    console.log(data.value, "youhj")
    yhjlist.value = data.value.rows;
    yhjlist.value.forEach(el => {
        el.start_time = format(el.start_time)
        el.end_time = format(el.end_time)
    })
}

const add0 = (m) => { return m < 10 ? '0' + m : m }
const format = (shijianchuo) => {
    //shijianchuo是整数，否则要parseInt转换
    var time = new Date(shijianchuo); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var y = time.getFullYear();
    var m = time.getMonth() + 1;
    var d = time.getDate();
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    return y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s);
}
</script>
<style scoped>
.yhjlist{
    width: 50%;
    margin-right: 10px;

}
.yhjlb{
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    padding: 20px;
    box-sizing: border-box;
}


.syzl {
    color: #fff;
}

.pricename {
    color: #fff;
    font-weight: bold;
    font-size: 20px;

}

.yhlist {
    width: 45%;
    height: 200px;
    margin-bottom: 15px;
    background: gray;
    border-radius: 10px;
    padding: 20px;
    box-sizing: border-box;
}

.yhjlist {
    width: 45%;
    height: 200px;
    margin-bottom: 15px;
    background: rgba(249, 115, 22, 1);
    border-radius: 10px;
    padding: 20px;
    box-sizing: border-box;
}

</style>